package com.xiaoyu.client.ui.dialog;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.xiaoyu.client.R;
import com.xiaoyu.client.ui.activity.main.mine.sign_and_help.SignActivity;

/**
 * 首页 -- 右上角弹窗
 */
public class SignShareMenuPow extends PopupWindow implements View.OnClickListener {
    private View mContentView;
    private ImageView homeSign, homeShare;
    private Context context;
    private IShareListener listener;

    public SignShareMenuPow(Context context) {
        super(context);
        this.context = context;
        initView(context);
    }

    //初始化元素
    private void initView(Context context) {
        mContentView = LayoutInflater.from(context).inflate(R.layout.sign_share_menu_pow, null);
        this.setContentView(mContentView);
        DialogUtils.showSchedulePow(this);//弹框样式

        homeSign = mContentView.findViewById(R.id.home_sign);
        homeShare = mContentView.findViewById(R.id.home_share);

        homeSign.setOnClickListener(this);
        homeShare.setOnClickListener(this);

    }

    public void show(View view) {
        if (!this.isShowing()) {
            this.showAsDropDown(view);
        } else {
            this.dismiss();
        }
    }

    @Override
    public void onClick(View view) {
        dismiss();
        //签到
        if (view == homeSign) {
            context.startActivity(new Intent(context, SignActivity.class));
        }
        //分享
        if (view == homeShare) {
            if (listener != null) {
                listener.OnShare();
            }
        }
    }
    public interface IShareListener {
        void OnShare();
    }

    public void setIShareListener(IShareListener listener) {
        this.listener = listener;
    }
}


